<?php
echo $this->adminToolBar('excursion', 'add', '/admin/excusion/ratefeatures/rate_id/'+rateid+'/hotelid/'+hotelid, '/admin/hotel/edit/', '/admin/hotel/delete/', '/admin/excursion/index/id/'.$this->id);
?>
<script language="javascript">
var counter = 1;
var limit = 100;
function addInput(divName,num) {
     if (counter == limit)   {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else  {
          var newdiv = document.createElement('div');
          var param="structkey_"+String(counter);
          newdiv.innerHTML = "<br>&nbsp;key  <input class='input-2' style='width: 200px;' type='text' name='exkey' id='exkey"+counter+"' />&nbsp;Text(EN)<textarea  name='exval' id='exval"+counter+"'></textarea>&nbsp;Text(Ru)<textarea  name='exval_ru' id='exval_ru"+counter+"'></textarea><br>";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
     }
}
</script>
<div class="mid-content" id="grid_rate">
<form method="post" id="myForm" action="">
       <br>

    <div id="dynamicInput">

<?php foreach($this->structarr as $arr):?>
       Key <input value="<?php echo $arr["exkey"] ;?>" class="input-2" style="width: 200px;" type="text" name="exkey" id="exkey" />
      &nbsp;Text (EN)<textarea  name='exval' id='exval'><?php echo $arr["exval"] ;?></textarea>
        &nbsp;Text (Ru)<textarea  name='exval_ru' id='exval_ru'><?php echo $arr["exval_ru"] ;?></textarea>
       <a  href="javascript: void(0);" onclick="deletestructurefield(<?php echo  $arr["id"]?>,<?php echo  $arr["excursionid"]?>);"><img src="images/icons/a-minus.gif" />Delete</a>
     
       <br>
     <?php endforeach;?>
    </div>

    <br>
    <input type="button" value="Add another field" onClick="addInput('dynamicInput',1);">
    <div>
	<td>&nbsp;<input type="hidden" name="id" id="id" value="<?php echo $this->id;?>" />
        </td>
	<td><div class="edit-icoset"><a href="javascript: void(0);" onclick="saveFeatures();"><img src="images/icons/save-2.gif" />Save</a></div>

        </td>
   </div>
</form>
    </div>

<script type="text/javascript">
function saveFeatures()
{
       var id=$('#id').val();
        var arr = $("form").serializeArray();
		$.ajax({
			type: "POST",
			url: '/admin/excursion/doaddexcursionfeatures/',
			data: ({postarray: arr}),
	    	        success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                               alert(data);
                             //  alert("successfully Added the   features");
	    			loadPage('/admin/excursion/excursionfeatures/id/<?php echo $this->id;?>');
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});

}


function deletestructurefield(id,exid)
{
		$.ajax({
			type: "POST",
			url: '/admin/excursion/deletestructuredata/',
			data: ({id:id}),
	    	        success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                               alert(data);
                              // alert('/admin/excursion/excursionfeatures/id/'+id);
	    			loadPage('/admin/excursion/excursionfeatures/id/'+exid);
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
    
}

</script>